#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:6031)

#include <cstring>
#include <utility>
#include <iostream>
using std::cout;
using std::endl;

class string
{
public:
	string(const char* str = "");
	string(const string& s);
	string& operator=(const string& s);
	~string();
	char* c_str() const;

private:
	char* m_str;

};

string::string(const char* str)
	: m_str(new char[strlen(str) + 1])
{
	memcpy(m_str, str, strlen(str) + 1);
}

string::string(const string& s)
	: m_str(new char[strlen(s.m_str) + 1])
{
	memcpy(m_str, s.m_str, strlen(s.m_str) + 1);
}

string::~string()
{
	delete[] m_str;
	m_str = nullptr;
}

string& string::operator=(const string& s)
{
	string tmp = s;
	std::swap(m_str, tmp.m_str);
	return *this;
}

char* string::c_str() const
{
	return m_str;
}

std::ostream& operator<<(std::ostream& out, string& s)
{
	out << s.c_str();
	return out;
}

int main()
{
	string s1("hello");
	cout << s1 << endl;
	string s2(s1);
	cout << s2 << endl;

	string s3("Carl");
	cout << s3 << endl;

	s3 = s2;
	cout << s3 << endl;



	return 0;
}
